package com.net.xpay.stat.scheduler;

import com.net.xpay.stat.task.CompanyBillDailyStatDailyTask;
import com.net.xpay.common.helper.NoticeHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 公司账单日常统计
 **/
@Slf4j
@Component
public class CompanyBillDailyStatScheduler {

    @Autowired
    private CompanyBillDailyStatDailyTask companyBillDailyStatDailyTask;

    @Autowired
    private NoticeHelper noticeHelper;


    @Scheduled(cron = "0 0 1 * * *")
    public void doCompanyBillStatDailyTask() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start schedule doCompanyBillStatDailyTask|now={}", LocalDateTime.now());
            companyBillDailyStatDailyTask.startDailyWork();
            long t2 = System.currentTimeMillis();
            log.info("end schedule doCompanyBillStatDailyTask|now={}|cost={}", LocalDateTime.now(), t2 - t1);
            noticeHelper.sendSystemInfoNotice("公司账单日常统计完成，耗费时间：" + (t2 - t1), "text");
        } catch (Throwable e) {
            log.warn("doCompanyBillStatDailyTask error", e);
            noticeHelper.sendSystemMonitorNotice("公司账单日常统计失败|doCompanyBillStatDailyTask error", "text");
        }
    }

}